/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mantenimiento.servlet.partes;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mantenimiento.dao.HistoriaDAO;
import mantenimiento.dao.ParteDAO;
import mantenimiento.excepcion.DAOExcepcion;
import mantenimiento.modelo.Fecha;
import mantenimiento.modelo.Historias;

/**
 *
 * @author Bakup
 */
public class PartesEliminarServlet extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet PartesEliminarServlet</title>");  
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet PartesEliminarServlet at " + request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");
            */
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
      ParteDAO dao = new ParteDAO();
		int id = Integer.parseInt(request.getParameter("idparte"));
		try {
			dao.eliminar(id);
			request.getRequestDispatcher("parte.jsp").forward(request,
					response);
		} catch (DAOExcepcion e) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
			rd.forward(request, response);
		}
                String usuario=request.getParameter("usuario");
                String nombre =request.getParameter("nombreH");
            System.out.println("nombre herramienta: "+nombre);
                            System.out.println("inicio--------------------------------------");

        Historias vo2 = new Historias();
        Fecha fe = new Fecha();
        System.out.println(usuario);
        System.out.println("xxxxxxxxxxxxxxxxxx--------------------------------------");
        vo2.setUsuario(usuario);
        System.out.println("xxxxxxxxxxxxxxxxxx--------------------------------------");
//        vo2.getUsuario()
        vo2.setAccion("Eliminar");
        vo2.setObjeto("Parte");
        vo2.setNom_objeto(nombre);
        vo2.setFecha(fe.getFecha());
        vo2.setHora(fe.getHora());
        HistoriaDAO hi = new HistoriaDAO();
        try {
            hi.insertar(vo2);
            System.out.println("se inserto la historia correctamente.");
        } catch (DAOExcepcion e1) {
            System.err.println("Error de historia");
        }
        System.out.println("hecho--------------------------------------");

    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
